package com.crm.system.controller.couponManager;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.couponManager.CouponIssued;
import com.crm.model.qo.couponManager.CouponIssuedQO;
import com.crm.model.qo.orderManager.CustomerProductOrderQO;
import com.crm.model.vo.couponManager.CouponIssuedVO;
import com.crm.model.vo.orderManager.CustomerProductOrderVO;
import com.crm.system.service.couponManager.CouponIssuedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author renshaorong
 * @Date 2021/11/8
 */
@RequestMapping("/couponissued")
@RestController
public class CouponIssuedController {

    @Autowired
    private CouponIssuedService couponIssuedService;


    /**
     * 客户拥有的优惠券列表
     * @return
     */
    @PostMapping("/couponIssuedPageList")
    public DataResponse selectFollowPlanList(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                             @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                             CouponIssued couponIssued//查询条件
    ){
        DhPageInfo<CouponIssuedVO> page = couponIssuedService.selectCouponIssuedPageList(couponIssued,pageIndex,pageSize,sortName,sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),page);
    }


    /**
     * 派发优惠券
     * @return
     */
    @PostMapping("/addCouponToCustomer")
    public JSONObject addCouponToCustomer(@RequestBody CouponIssuedQO couponIssuedQO){
        return couponIssuedService.addCouponToCustomer(couponIssuedQO);
    }

    /**
     * 订单列表
     * @return
     */
    @PostMapping("/selectCustomerProductOrder")
    public DataResponse selectCustomerProductOrder(@RequestParam(value = "pageIndex", required = true) Integer pageIndex,//页码
                                             @RequestParam(value = "pageSize", required = true) Integer pageSize,//分页大小
                                             @RequestParam(value="sortName",required = false) String sortName,//排序列名字
                                             @RequestParam(value="sortOrder",required = false) String sortOrder,//排序规则(asc/desc)
                                                   CustomerProductOrderQO customerProductOrderQO//查询条件
    ){
        List<String> productLists = JSONArray.parseArray(customerProductOrderQO.getProductLists(), String.class);
        customerProductOrderQO.setProductList(productLists);
        DhPageInfo<CustomerProductOrderVO> customerProductOrderVODhPageInfo = couponIssuedService.selectCustomerProductOrder(pageIndex, pageSize, customerProductOrderQO, sortName, sortOrder);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),customerProductOrderVODhPageInfo);
    }
}
